package ai.loa.utility;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Properties;
import java.util.Set;

public class IndependentFeatures {
	public static HashMap<Long, Integer> cache;
	private static String fileProperties = "cache";
	static {
		try {
			cache = new HashMap<Long, Integer>(600000);
			Properties prop = new Properties();
			prop.load(new FileInputStream(fileProperties));
			Set<Object> l = prop.keySet();
			for (Object o : l) {
				long k = Long.parseLong((String) o);
				int val = Integer.parseInt((String) prop.get(o));
				cache.put(k, val);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void save() {
		try {
			Set<Long> l = cache.keySet();
			Properties prop = new Properties();
			for (Long l1 : l) {
				prop.put(""+l1, ""+cache.get(l1));
			}
			prop.store(new FileOutputStream(fileProperties), null);
			System.out.println("Cache salvata");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
